package com.lu.statistics.controller;

import com.lu.statistics.common.config.ServerResponse;
import com.lu.statistics.entity.SysDictItem;
import com.lu.statistics.entity.front.response.DictItemResponse;
import com.lu.statistics.service.SysDictItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 系统数据字典详情
 */
@Api(value = "字典详情模块", tags = {"字典详情模块"})
@RestController
@RequestMapping("/api/dictItem")
public class SysDictItemController {
    @Autowired
    private SysDictItemService dictItemService;
    @ApiOperation(value = "查询字典详情(下拉框回显)", notes = "查询字典详情(下拉框回显)")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", required = true, name = "dictCode", value = "字典编号", dataType = "string")})
    @GetMapping(value = "/queryDictItem")
    public ServerResponse<List<DictItemResponse>> queryDictItem(String dictCode) {
            List<SysDictItem> itemList = dictItemService.queryDictItem(dictCode);
            List<DictItemResponse> newList = new ArrayList<>();
            if (itemList != null && itemList.size() > 0) {
                for (SysDictItem item : itemList) {
                    DictItemResponse itemResponse = new DictItemResponse();
//                    BeanUtils.copyProperties(item, itemResponse);
                    itemResponse.setId(item.getId());
                    itemResponse.setText(item.getItemName());
                    itemResponse.setValue(item.getKey());

                    newList.add(itemResponse);
                }
            }

        return ServerResponse.success(newList);
    }
}
